<template>
  <div style="padding:30px; width:50%; margin:0 auto">
    <el-form ref="form" :model="form" label-width="80px" label-position="left">
      <el-form-item label="用户名称">{{ form.userName }}</el-form-item>
      <el-form-item label="入库管理">
        <el-switch v-model="form.inWarehouse"></el-switch>
      </el-form-item>
      <el-form-item label="出库管理">
        <el-switch v-model="form.outWarehouse"></el-switch>
      </el-form-item>
      <el-form-item label="物资处理">
        <el-switch v-model="form.goods"></el-switch>
      </el-form-item>
      <el-form-item label="查询统计">
        <el-switch v-model="form.statistics"></el-switch>
      </el-form-item>
      <el-form-item label="基础信息">
        <el-switch v-model="form.basic"></el-switch>
      </el-form-item>
      <el-form-item label="系统管理">
        <el-switch v-model="form.system"></el-switch>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button>重置</el-button>
        <el-button>返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
  
<script>
import { updateUser } from "@/api/user";
export default {
  data() {
    return {
      form: {}
    };
  },
  created() {
    console.log(this.$route.params.userInfo)
    this.form = JSON.parse(sessionStorage.getItem("USER_INFO")) || this.$route.params.userInfo
  },
  methods: {
    async onSubmit() {
      for (let key in this.form) {
        if (this.form[key] == true) {
          this.form[key] = '1';
        } else if (this.form[key] == false) {
          this.form[key] = '0';
        }
      }
      console.log(this.form)
      let res = await updateUser(this.form);
      console.log(res)
      this.$router.push({ path: "/manage/users"})
    },
  }
};
</script>